package com.dbManage.page.essay;

import com.dbManage.dao.EssayDao;
import com.dbManage.entity.Note;
import com.dbManage.entity.User;
import com.dbManage.tools.SessionTool;
import com.wsse.common.tool.TimeTool;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class EssayService {
    @Resource
    EssayDao essayDao;


    public void addEssay(Note note) {
        User user = SessionTool.getUser();
        note.setAddId(user.getId());
        note.setAddName(user.getNickName());
        note.setTime(TimeTool.getNow());
        essayDao.insertEssay(note);
    }

    public void updateEssay(Note note) {
        note.setTime(TimeTool.getNow());
        essayDao.updateEssayById(note);
    }

    public List<Note> queryEssay(Note note) {
        if (note == null) {
            note = new Note();
        }
        note.setAddId(SessionTool.getUser().getId());
        return essayDao.queryEssay(note);
    }
}
